/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ProyectoFinal.Implementacion;

/**
 *
 * @author Martin
 */

import java.sql.*;


public class Conexion {
    private String user;
    private String pass;
    private String db;
    private String host;
    private String url;
    private Connection conn = null;
    public Statement stm;

    public Conexion() {
        this("beche13","lynxius945","proyectolasheras","www.db4free.net");
    }
   
    public Conexion(String user, String pass, String db, String host) {
        this.user = user;
        this.pass = pass;
        this.db = db;
        this.host = host;
    }

    public void conectar() {
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
            conn = DriverManager.getConnection(url, user, pass);
            if (conn != null) {
                System.out.println("Conexión a base de datos " + url + " ... Ok");
                stm = conn.createStatement();
            }
        } catch (SQLException ex) {
            System.out.println("Hubo un problema al intentar conectarse con la base de datos " + url);
        } catch (ClassNotFoundException ex) {
            System.out.println(ex);
        }
    }

    public ResultSet consultar(String consulta) throws SQLException {
        return stm.executeQuery(consulta);
    }

    public void insertar(String consulta) throws SQLException {
        stm.executeUpdate(consulta);
    }

    public void actualizar(String consulta) throws SQLException {
        stm.executeUpdate(consulta);
    }
    
    public Connection getConn() {
        return conn;
    }
    
    
}
